package com.parkinglot.biz;

import com.parkinglot.dao.OrderDao;
import com.parkinglot.util.DatesUtil;
import com.parkinglot.vo.IncomeStatisticsVo;
import com.parkinglot.vo.SelectIncomeByTimeVo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

@Component
public class IncomeStatistics extends Statistics{
    @Resource
    private OrderDao orderDao;


    @Override
    protected void statistics(StatisticsContext context) {
        LinkedHashMap<String, BigDecimal> map = new LinkedHashMap();
        for (String hours : DatesUtil.hours) {
            map.put(hours, BigDecimal.ZERO);
        }
        List<SelectIncomeByTimeVo> vos = orderDao.selectIncomeByTime(context);
        for (SelectIncomeByTimeVo vo : vos) {
            map.put(vo.getHours(), vo.getAmount());
        }
        List<String> nameList = new ArrayList<>(25);
        List<BigDecimal> valueList = new ArrayList<>(25);

        for(Map.Entry<String, BigDecimal> entry : map.entrySet()){
            nameList.add(entry.getKey());
            valueList.add(entry.getValue());
        }
        context.setResult(new IncomeStatisticsVo(nameList,valueList));
    }
}
